package com.yuwj.chinaa.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.Toolbar;
import android.widget.TextView;

import com.yuwj.chinaa.R;
import com.yuwj.chinaa.base.BaseActivity;
import com.yuwj.chinaa.entity.EntityNews;
import com.yuwj.chinaa.presenter.IPresenter;
import com.yuwj.chinaa.presenter.presenterImpl.PresenterImpl;
import com.yuwj.chinaa.util.DateUtil;
import com.yuwj.chinaa.util.ToastUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Calendar;
import java.util.Date;

import butterknife.BindView;

public class NewsDetailActivity extends BaseActivity {


    IPresenter presenter;
    EntityNews entityNews;
    @BindView(R.id.tv_news_title)
    TextView tvNewsTitle;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_content)
    TextView tvContent;
    Calendar calendar;

    public static Intent createIntent(Context context, EntityNews entityNews) {
        Intent intent = new Intent(context, NewsDetailActivity.class);
        intent.putExtra("entityNews", entityNews);
        return intent;
    }

    @Override
    public int setCustomContentViewResourceId() {
        return R.layout.activity_news_detail;
    }

    @Override
    public void initParam() {
        Intent intent = getIntent();
        entityNews = (EntityNews) intent.getSerializableExtra("entityNews");
        presenter = new PresenterImpl(this);
        calendar = Calendar.getInstance();
    }

    @Override
    public void initView() {
        tvNewsTitle.setText(entityNews.getNewTitle());
        tvTime.setText(entityNews.getCreateTime());
        tvContent.setText(entityNews.getNewDes());
    }

    @Override
    public void initOperator() {
        JSONObject param = new JSONObject();
        try {
            param.put("newid", entityNews.getID()+"");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        presenter.getNewsDetail(param.toString());
    }


    @Override
    public void onGetNewsDetailSuccess(EntityNews entityNews) {
        super.onGetNewsDetailSuccess(entityNews);
        this.entityNews=entityNews;
        initView();
    }

    @Override
    public void onGetNewsDetailFail(Exception e) {
        super.onGetNewsDetailFail(e);
        ToastUtil.getInstance().shortLength(context,e.getMessage());
    }
}
